function userInBuild() {
  var ie6 = ($.browser.msie && $.browser.version == '6.0') ? 90 : 0;
  var tabsHeight = (ie6 == 90) ? 0 : ($('#tabs').offset().top + $('#tabs').height());
  var downLists = $('#menuList > ul');
  downLists.hover(function(){
    window.__ishover = true;
  },function(){
    jQuery.fx.off = window.__ishover = false;
    downLists.hide();
  }).find('a').click(function(){
    if(ie6 > 0) return true;
    var hash = document.getElementsByName(this.hash.replace('#',''))[0];
    if(hash) window.scrollTo(0,$(hash.parentNode).offset().top - tabsHeight);

    return false;
  });

  $('#topTabs a').hover(function(){
    window.__ishover = true;
    $('#menuList ul').hide();
    downList = $('#childId'+$(this).parent()[0].tabIndex);
    var offset = $(this).position();
    downList.css('top',offset.top + 25 + ie6);
    downList.css('left',offset.left);
    downList.show();
  },function(){
    setTimeout(function(){if(!window.__ishover) downLists.hide();},1500);
  });

  window.empList = $('#empList');
  window.addDelSpan = $('#addDelSpan');
  $('#sb_form_q')[0].onkeyup = function () {
    var v = this.value;
    v = v.replace(/([\\\(\)\[\]\+\*\^\$\?\.])/ig,'\\$1');
    var rows = empList[0].rows || [],len = rows.length;
    if(len == undefined) {rows = [rows];len = 1;}
    if(v == '') $('#menuList').show();
    else $('#menuList').hide();

    var reg = new RegExp(v, "ig");
    for (var i = 0; i < len; i++) {
      var r = rows[i];
      r.style.display = (v == '' || ((r.innerText || r.textContent).replace(/\s/g,"").search(reg) > -1))? '' : 'none';
    }
  };

  $('#addImg').click(function(){
    if(!window.currEditRow) return false;
    var rowIndex = reDraw(true);
    var tr = empList[0].insertRow(window.currEditRow.rowIndex+1);
    tr.insertCell(0).innerHTML= rowIndex;
    for(var j=1; j < 9; j++)
      tr.insertCell(j).innerHTML= '<input type="text" size="7"/>';
    addDelSpan.hide();
  });

  var delImg = $('#delImg').click(function(){
    reDraw();
    $.ajaxSetup({async: false});
    $.get('/getEmpById/' + window.currEditRow.id.replace("empId",""), function(data) {
      if(confirm('确定删除:' + data)) {
          $.get('/deleteEmp/' + window.currEditRow.id.replace("empId",""), function(d2){
            $(window.currEditRow).remove();
            showTip(d2);
          });
      }
    });
    addDelSpan.hide();
  });

  function reDraw(isAdd) {
    var nextRow = $(window.currEditRow).next()[0]; //window.currEditRow.nextSibling;
    var rowIndex = window.currEditRow.cells[0].innerHTML;
    rowIndex = /^\d+$/.test(rowIndex) ? (parseInt(rowIndex) + 1) : 1,rowIndex_ = rowIndex;
    if(!isAdd) rowIndex -= 2;
    while(nextRow && nextRow.nodeType == 1 && nextRow.cells[0].colSpan == 1) {
      nextRow.cells[0].innerHTML = ++rowIndex;
      nextRow = $(nextRow).next()[0];
    }
    return rowIndex_;
  }

  empList.bind('mouseover',function(event) {
    var src = event.srcElement || event.target;
    if(_isEdit_ && /^td$/i.test(src.tagName)) { //_isEdit_ && && src.colSpan == 9
      addDelSpan.show();
      window.currEditRow = src.parentNode;
      var offset = $(src.parentNode).offset();
      addDelSpan[0].style.top = offset.top + 3 + 'px';
      addDelSpan[0].style.left = offset.left + 3 + 'px';
      if(src.colSpan == 9) {
        delImg.hide();
        if($(src).text().length == 1)
          addDelSpan.hide();
      }
      else delImg.show();
    }
    //showTip($(src).text(),true);
  });

  window._isEdit_ = false;
  $('#editSpan').click(function(){
    //if(prompt('请输入修改密码:','') != '文昱') return alert("密码不对");
    //this.style.display = 'none';
    $('#saveSpan')[0].style.display = 'inline';
    $('#cancelSpan')[0].style.display = 'inline';
    edit(true);
  });
  $('#saveSpan').click(function(){
    this.style.display = 'none';
    //$('#editSpan')[0].style.display = 'inline';
    $('#cancelSpan')[0].style.display = 'none';
    $('#empList').removeClass('edit');
    save();
    edit(false);
  });
  $('#cancelSpan').click(function(){
    this.style.display = 'none';
    //$('#editSpan')[0].style.display = 'inline';
    $('#saveSpan')[0].style.display = 'none';
    edit(false);
  });
  $("#cloceDivTip").click(showTip);

  function edit(e){
    window._isEdit_ = e;
    if(e) {
        empList.addClass('edit');
        //$("#cloceDivTip").text('当前选取');
    } else {
      empList.removeClass('edit');
      addDelSpan.hide();
        //$("#cloceDivTip").text('取消');
    }
    //var spans = empList[0].getElementsByTagName('span'),len = spans.length;
    //for(var i=0; i < len; i++)
      //spans[i].contentEditable = e;
  }

  function save(){

  }

  if ($.browser.msie) empList.find('TD:nth-child(2)').css('text-align','left');
  if(ie6 > 0)  {
    empList.find('TD[colspan="9"][align]').css({'background-color': '#019271','color': '#FFFFFF','text-align': 'center', 'font-weight': 'bold'});
    //$('br').remove();
  }
  if(ie6 > 0) $('#clearDivID').hide();
}

function showTip(tip,time){
  var divTip = $("#divTip");
  if(divTip.is(":hidden")) $('#divInfo').html(tip);
  if(time === true) return tip.length > 1 && divTip.slideDown() && $('#divInfo').html(tip);
  divTip.slideToggle('slow');
  //if(tip && typeof tip == 'string') setTimeout(showTip,time || 5000);
}
$.ajaxSetup({async: false});
$(userInBuild);


